//
//  EruptDiseaseCell.m
//  FastDoctor
//
//  Created by 李通 on 16/7/8.
//  Copyright © 2016年 sc. All rights reserved.
//

#import "EruptDiseaseCell.h"
#import "EruptDTO.h"

@interface EruptDiseaseCell ()

@property (nonatomic,weak) UIButton *subscribeButton;

@property (nonatomic,weak) UILabel *diseaseTitle;

@end

@implementation EruptDiseaseCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupContents];
    }
    return self;
}

- (void)setupContents {
    
    
//    UITextField *field = [[UITextField alloc]init];
////    field.userInteractionEnabled = NO;
//    self.diseaseTitle = field;
    UIButton *button = [[UIButton alloc]init];
        self.subscribeButton = button;
    [button setBackgroundImage:[UIImage imageNamed:@"nav"] forState:UIControlStateNormal];
    [button setTitle:@"订阅" forState:UIControlStateNormal];
    [button setTitleColor:WHITE_COLOR forState:UIControlStateNormal];
    [button addTarget:self
               action:@selector(didClickButton:)
     forControlEvents:UIControlEventTouchUpInside];
    
//    field.rightView = button;
//    field.rightViewMode = UITextFieldViewModeAlways;
    
    [self.contentView addSubview:button];
    UILabel *label = [[UILabel alloc]init];
    self.diseaseTitle = label;
    [self.contentView addSubview:label];
    
    [self setupUI];
}

- (void)setupUI {
    
    [self.subscribeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.equalTo(self.contentView.mas_centerY);
        make.trailing.equalTo(self.contentView).offset(-20);
        make.width.mas_equalTo(80);
        make.height.mas_equalTo(30);
    }];

    [self.diseaseTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.leading.equalTo(self.contentView).offset(20);
        make.centerY.equalTo(self.contentView.mas_centerY);
        make.height.mas_equalTo(30);
        make.trailing.equalTo(self.subscribeButton.mas_leading).offset(-20);
    }];
}

- (void)setEruptModel:(EruptDTO *)eruptModel {
    
    _eruptModel = eruptModel;
    
    self.diseaseTitle.text = eruptModel.complication_name;
}

- (void)didClickButton:(UIButton *)button {
    
    if ([self.eruptDelegate respondsToSelector:@selector(didClickEruptDiseaseCellButton:withLabel:)]) {
       
        [self.eruptDelegate didClickEruptDiseaseCellButton:button withLabel:self.diseaseTitle];
    }
}

@end
